// pages/myTask/myTask.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    myTask: {
      reward_logo: '../../images/experience.png',
      task: '../../images/5.png',
    },
    list: [
      {
        id: 'one',
        type: 1,   //进行中
        open: false,
      },
      {
        id: 'two',
        type: 2,   //完成
        open: false,
      },
      {
        id: 'three',
        type: 3,  //领取奖励
        open: false,
      },
      {
        id: 'four',
        type: 4,  //查看奖励
        open: false, 
      }   
    ],
    hideModal: true,
    modalId: 'one',
    modalIdTemp: '',
    success: '../../images/success2.png',
    experience: '../../images/experience2.png',
    bonus: '../../images/bonus.png',
  },

  /**
   * 点击展开
   */
  kindToggle: function (e) {
    var id = e.currentTarget.id, list = this.data.list;
    this.setData({
      modalIdTemp: id
    });
    //点击按钮不展开
    if (e.target.id == 'btn_take') {
      return;
    }
    for (var i = 0, len = list.length; i < len; ++i) {
      if (list[i].id == id) {
        list[i].open = !list[i].open
      }
    }
    this.setData({
      list: list,
      modalIdTemp: id
    });
  },

  /**
   * 查看奖励
   */
  lookReward: function () {
    wx.navigateTo({
      url: '../receivePrivilege/receivePrivilegeList'
    })
  },

  /**
   * 立即领取
   */
  getReward: function (e) {
    var that = this
    that.setData({
      hideModal: !that.data.hideModal,
    })
  },

  /**
   * 点击空白处关闭
   */
  clickBlank: function (e) {
    var id = e.target.id
    var that = this, list = this.data.list;
    if (id == 'one') {
      this.setData({
        hideModal: true,
      })
      for (var i = 0, len = list.length; i < len; ++i) {
        if (list[i].id == that.data.modalIdTemp) {
          if (list[i].type == 3) {
            list[i].type = 1
            this.setData({
              list: list
            })
          }
        }
      }
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
  
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})